/*
 * Sound.h
 */
#include "ail\dll.h"
#include "ail\ail.h"

#define SMMEMORYSIZE 1450000

/* Define kinds of sound effect */
#define NUMEFFECT	12
#define NUMFX       41
#define NUMCLUES	139

#define LOADED_CLUES        0x0001
#define LOADED_EFFECTS      0x0002
#define LOADED_SCENEMUSIC   0x0004

#define LOADED_ALLSOUND     0x0007

#define N_VOICES 15		  	// # of mixer channels to allocate
#define CLUE	12				// offset into snd array for clues
#define SMUSIC 13				// offset into snd array for scenemusic
#define REPLAY 31

#define CD_CLUE_START	0 
#define CD_CLUE_END		1
#define CN_CLUE_START	2
#define CN_CLUE_END		6
#define GW_CLUE_START	7
#define GW_CLUE_END		11
#define PO_CLUE_START	12
#define PO_CLUE_END		14
#define IN_CLUE_START	15
#define IN_CLUE_END		36
#define DC_CLUE_START	37
#define DC_CLUE_END		58
#define CL_CLUE_START	59
#define CL_CLUE_END		75
#define PD_CLUE_START	76
#define PD_CLUE_END		103
#define FW_CLUE_START	104
#define FW_CLUE_END		114
#define FC_CLUE_START	115
#define FC_CLUE_END		125
#define IW_CLUE_START	126
#define IW_CLUE_END		132
#define ME_CLUE_START	133
#define ME_CLUE_END		138

#define COCLUE0  0
#define COCLUE1  1

#define CACLUE0  2
#define CACLUE1  3
#define CACLUE2  4
#define CACLUE3  5
#define CACLUE4  6

#define GWCLUE0  7 
#define GWCLUE1  8
#define GWCLUE2  9
#define GWCLUE3  10
#define GWCLUE4  11

#define POCLUE0  12
#define POCLUE1  11
#define POCLUE2  14

#define INCLUE0  15
#define INCLUE1  16
#define INCLUE2  17 
#define INCLUE3  18 
#define INCLUE4  19 
#define INCLUE5  20 
#define INCLUE6  21 
#define INCLUE7  22 
#define INCLUE8  23 
#define INCLUE9  24 
#define INCLUE10 25 
#define INCLUE11 26 
#define INCLUE12 27 
#define INCLUE13 28 
#define INCLUE14 29 
#define INCLUE15 30 
#define INCLUE16 31
#define INCLUE17 32
#define INCLUE18 33
#define INCLUE19 34
#define INCLUE20 35
#define INCLUE21 36

#define DCCLUE0  37 
#define DCCLUE1  38 
#define DCCLUE2  39 
#define DCCLUE3  40 
#define DCCLUE4  41 
#define DCCLUE5  42 
#define DCCLUE6  43 
#define DCCLUE7  44 
#define DCCLUE8  45 
#define DCCLUE9  46 
#define DCCLUE10 47 
#define DCCLUE11 48 
#define DCCLUE12 49 
#define DCCLUE13 50 
#define DCCLUE14 51 
#define DCCLUE15 52 
#define DCCLUE16 53 
#define DCCLUE17 54 
#define DCCLUE18 55 
#define DCCLUE19 56 
#define DCCLUE20 57 
#define DCCLUE21 58 

#define CICLUE0  59 
#define CICLUE1  60 
#define CICLUE2  61 
#define CICLUE3  62 
#define CICLUE4  63 
#define CICLUE5  64 
#define CICLUE6  65 
#define CICLUE7  66 
#define CICLUE8  67 
#define CICLUE9  68 
#define CICLUE10 69 
#define CICLUE11 70 
#define CICLUE12 71 
#define CICLUE13 72 
#define CICLUE14 73 
#define CICLUE15 74 
#define CICLUE16 75 

#define PDCLUE0  76 
#define PDCLUE1  77 
#define PDCLUE2  78 
#define PDCLUE3  79 
#define PDCLUE4  80 
#define PDCLUE5  81 
#define PDCLUE6  82 
#define PDCLUE7  83 
#define PDCLUE8  84 
#define PDCLUE9  85 
#define PDCLUE10 86 
#define PDCLUE11 87 
#define PDCLUE12 88 
#define PDCLUE13 89 
#define PDCLUE14 90 
#define PDCLUE15 91 
#define PDCLUE16 92 
#define PDCLUE17 93 
#define PDCLUE18 94 
#define PDCLUE19 95 
#define PDCLUE20 96
#define PDCLUE21 97 
#define PDCLUE22 98 
#define PDCLUE23 99 
#define PDCLUE24 100 
#define PDCLUE25 101 
#define PDCLUE26 102 
#define PDCLUE27 103 

#define FWCLUE0  104 
#define FWCLUE1  105 
#define FWCLUE2  106 
#define FWCLUE3  107 
#define FWCLUE4  108 
#define FWCLUE5  109
#define FWCLUE6  110
#define FWCLUE7  111
#define FWCLUE8  112
#define FWCLUE9  113
#define FWCLUE10 114

#define FCCLUE0  115
#define FCCLUE1  116
#define FCCLUE2  117
#define FCCLUE3  118
#define FCCLUE4  119
#define FCCLUE5  120
#define FCCLUE6  121
#define FCCLUE7  122
#define FCCLUE8  123
#define FCCLUE9  124
#define FCCLUE10 125

#define IWCLUE0  126
#define IWCLUE1  127
#define IWCLUE2  128
#define IWCLUE3  129
#define IWCLUE4  130
#define IWCLUE5  131
#define IWCLUE6  132

#define MECLUE0  133
#define MECLUE1  134
#define MECLUE2  135
#define MECLUE3  136
#define MECLUE4  137
#define MECLUE5  138

#define CD_FX_START	0 
#define CD_FX_END		4
#define CN_FX_START	0
#define CN_FX_END		4
#define GW_FX_START	0
#define GW_FX_END		5
#define PO_FX_START	6
#define PO_FX_END		17
#define IN_FX_START	18
#define IN_FX_END		29
#define DC_FX_START	18
#define DC_FX_END		29
#define CL_FX_START	18
#define CL_FX_END		29
#define PD_FX_START	18
#define PD_FX_END		29
#define FW_FX_START	18
#define FW_FX_END		29
#define IW_FX_START	18
#define IW_FX_END		29
#define FC_FX_START	30
#define FC_FX_END		40

enum {S_CYBERGUN,
      S_EXPLOSION,
	  S_TOOL,
	  S_RETRIEVE,
	  S_RECONGUN,
	  S_LIGHTNING,
	  S_POD,
	  S_SCRAPE,
	  S_GROWL };

enum { RW_JETFLYBY=2,RW_2SWOOP,RW_SWOOSH,RW_POWERGRID };

enum { PO_LIGHTNING=4,PO_POD,PO_RECONGUN,PO_RECONPAT,PO_WAIL };

#ifdef _SOUND_

char *g_effectname[NUMFX] =
{
	"\\data\\sound\\cybergun.wav",  //0// REAL WORLD - COASTAL THRU GREATWALL
	"\\data\\sound\\expl.wav",		  //1
	"\\data\\sound\\jetflyby.wav",  //2 
	"\\data\\sound\\2swoop.wav",	  //3
	"\\data\\sound\\swoosh.wav",	  //4
	"\\data\\sound\\powrgrid.wav",  //5
	
	"\\data\\sound\\cybergun.wav",  //6// starting CYBERSPACE  PORTAL	
	"\\data\\sound\\expl.wav",		  //7
	"\\data\\sound\\tool.wav",		  //8
	"\\data\\sound\\retrieve.aif",  //9
	"\\data\\sound\\recongun.wav",  //12
	"\\data\\sound\\zap.wav",		  //10
	"\\data\\sound\\pod.wav",		  //11
	"\\data\\sound\\stratos.wav",	  //13
	"\\data\\sound\\portrio.wav",	  //14
	"\\data\\sound\\pochase.wav",	  //15
	"\\data\\sound\\portdoor.wav",  //16
	"\\data\\sound\\launch.wav",	  //17
	
	"\\data\\sound\\cybergun.wav",  //18  INFONET THRU INWALL (FCON SEPARATE)
	"\\data\\sound\\expl.wav",		  //19
	"\\data\\sound\\tool.wav",		  //20
	"\\data\\sound\\retrieve.aif",  //21
	"\\data\\sound\\recongun.wav",  //22
	"\\data\\sound\\zap.wav",		  //23
	"\\data\\sound\\stratos.wav",	  //24
	"\\data\\sound\\creepy.wav",	  //25
	"\\data\\sound\\forcepat.wav",  //26
	"\\data\\sound\\reconpat.wav",  //27
	"\\data\\sound\\wail.wav",		  //28
	"\\data\\sound\\weegrowl.wav",  //29

	"\\data\\sound\\cybergun.wav",  //30// FINAL CONFLICT
	"\\data\\sound\\expl.wav",		  //31
	"\\data\\sound\\tool.wav",		  //32
	"\\data\\sound\\retrieve.aif",  //33
	"\\data\\sound\\recongun.wav",  //34
	"\\data\\sound\\wail.wav",		  //35
	"\\data\\sound\\stratos.wav",	  //36
	"\\data\\sound\\creepy.wav",	  //37
	"\\data\\sound\\forcepat.wav",  //38
	"\\data\\sound\\reconpat.wav",  //39
	"\\data\\sound\\fctunnel.wav"	  //40
};

//char *g_effectname[NUMEFFECT] =
//{
//	"\\data\\sound\\cybergun.wav",  	//0
//	"\\data\\sound\\expl.wav",			//1
//	"\\data\\sound\\zap.wav",			//2
//	"\\data\\sound\\pod.wav",			//3
//	"\\data\\sound\\wail.wav",			//4
//	"\\data\\sound\\stratos.wav",		//5
//	"\\data\\sound\\creepy.wav",		//6
//	"\\data\\sound\\recongun.wav",	//4
//	"\\data\\sound\\retrieve.aif",	//5
//	"\\data\\sound\\swoosh.wav",		//6
//	"\\data\\sound\\forcepat.wav",	//7
//	"\\data\\sound\\reconpat.wav"		//8
//	"\\data\\sound\\new2swoo.wav"		//7
//	"\\data\\sound\\new2swoo.wav"		//8
//	"\\data\\sound\\jetflyby.wav",	//7
//	"\\data\\sound\\2swoop.wav"		//8
//};

char *g_music[12] =
{
	"\\data\\sound\\coastal.wav",
	"\\data\\sound\\canyon.wav",
	"\\data\\sound\\gwall.wav",
	"\\data\\sound\\portal.wav",
	"\\data\\sound\\infonet.wav",
	"\\data\\sound\\col.wav",
	"\\data\\sound\\dc.wav",
	"\\data\\sound\\pd.wav",
	"\\data\\sound\\firewal.wav",
	"\\data\\sound\\inwall.wav",
	"\\data\\sound\\fcon.wav",
	"\\data\\sound\\mainm.wav"
};
char *g_clue[NUMCLUES] =
{											//struct number    (clue number in scene)
	"\\data\\sound\\cl63.wav",		// COASTAL! 0,1	 (0)
	"\\data\\sound\\cl59.wav",  	//1					 (1)

	"\\data\\sound\\cl53.wav",		// CANYON! 2 - 6   (0)
	"\\data\\sound\\cl66.wav",		//3  				    (1)
	"\\data\\sound\\cl65.wav",		//4					 (2)
	"\\data\\sound\\cl67.wav",		//5					 (3)
	"\\data\\sound\\rd200.wav", 	//6					 (4)

	"\\data\\sound\\rd100.wav",  	// GWALL! 7 - 11   (0) 
	"\\data\\sound\\rd99.wav",		//8					 (1)
	"\\data\\sound\\rd102.wav",	//9					 (2)
	"\\data\\sound\\rd101.wav",	//10					 (3)
	"\\data\\sound\\rd201.wav",	//11					 (4)

	"\\data\\sound\\rd95.wav",		// PORTAL! 12- 14  (0)
	"\\data\\sound\\rd94.wav",		//13					 (1)
	"\\data\\sound\\ha156.wav",	//14					 (2)

	"\\data\\sound\\ha157.wav",	// INFONET! 15-36  (0)
	"\\data\\sound\\ha158.wav",	//16					 (1)
	"\\data\\sound\\ha159.wav",	//17					 (2)
	"\\data\\sound\\ha160.wav",	//18					 (3)
	"\\data\\sound\\ha161.wav",	//19					 (4)
	"\\data\\sound\\rd113.wav",	//20					 (5)
	"\\data\\sound\\rd115.wav",	//21					 (6)
	"\\data\\sound\\ai77a.wav",	//22					 (7)
	"\\data\\sound\\ai78b.wav",	//23					 (8)
	"\\data\\sound\\rd111.wav",	//24					 (9)
	"\\data\\sound\\rd112.wav",	//25					 (10)
	"\\data\\sound\\rd117.wav",	//26					 (11)
	"\\data\\sound\\rd118.wav",	//27					 (12)
	"\\data\\sound\\rd119.wav",	//28					 (13)
	"\\data\\sound\\rd120.wav",	//29					 (14)
	"\\data\\sound\\rd121.wav",	//30					 (15)
	"\\data\\sound\\rd107.wav",	//31					 (16)
	"\\data\\sound\\rd202.wav",	//32					 (17)
	"\\data\\sound\\rd203.wav",	//33					 (18)
	"\\data\\sound\\rd204.wav",	//34					 (19)
	"\\data\\sound\\rd205.wav",	//35					 (20)
	"\\data\\sound\\rd206.wav",	//36					 (21)

	"\\data\\sound\\rd84c.wav",	// DATA CLN! 37-58 (0) 
	"\\data\\sound\\rd126.wav",	//38					 (1)
	"\\data\\sound\\rd128.wav",	//39					 (2)
	"\\data\\sound\\cl36b.wav",	//40					 (3)
	"\\data\\sound\\rd82a.wav",	//41					 (4)
	"\\data\\sound\\cl33.wav",	//42					 (5)
	"\\data\\sound\\rd82c.wav",	//43					 (6)
	"\\data\\sound\\cl36d.wav",	//44					 (7)
	"\\data\\sound\\rd79a.wav",	//45					 (8)
	"\\data\\sound\\cl53.wav",	//46					 (9)
	"\\data\\sound\\rd79a.wav",	//47					 (10)
	"\\data\\sound\\oc9.wav",   //48					 (11)  // this was oc9a!!
	"\\data\\sound\\ha161.wav",	//49					 (12)
	"\\data\\sound\\ha162.wav",	//50					 (13)
	"\\data\\sound\\rd123.wav",	//51					 (14)
	"\\data\\sound\\rd125.wav",	//52					 (15)
	"\\data\\sound\\rd127.wav",	//53					 (16)
	"\\data\\sound\\ai77c.wav",	//54					 (17)
	"\\data\\sound\\rd114b.wav",//55					 (18)
	"\\data\\sound\\rd108.wav",	//56					 (19)
	"\\data\\sound\\ha163.wav",	//57					 (20)
	"\\data\\sound\\rd207.wav",	//58					 (21)

	"\\data\\sound\\rd82a.wav",	// CITY LIT! 59-75 (0)
	"\\data\\sound\\cl40.wav",	//60					 (1)
	"\\data\\sound\\rd79a.wav",	//61					 (2)
	"\\data\\sound\\rd82a.wav",	//62					 (3)
	"\\data\\sound\\rd79b.wav",	//63					 (4)
	"\\data\\sound\\cl36b.wav",	//64					 (5)
	"\\data\\sound\\rd135.wav",	//65					 (6)
	"\\data\\sound\\rd138.wav",	//66					 (7)
	"\\data\\sound\\rd108.wav",	//67					 (8)
	"\\data\\sound\\cl54.wav",	//68					 (9)
	"\\data\\sound\\cl55.wav",	//69					 (10)
	"\\data\\sound\\cl56.wav",	//70					 (11)
	"\\data\\sound\\rd131.wav",	//71					 (12)
	"\\data\\sound\\rd132.wav",	//72					 (13)
//	"\\data\\sound\\rd133.wav",	//73					 (14)
	"\\data\\sound\\rd203.wav",	//33					 (14)
	"\\data\\sound\\rd136.wav",	//74					 (15)
	"\\data\\sound\\rd127.wav",	//75					 (16)

	"\\data\\sound\\rd84e.wav",	// PERIM! 76-103	 (0)
	"\\data\\sound\\rd82a.wav",	//77					 (1)
	"\\data\\sound\\cl27.wav",	//70					 (2)
	"\\data\\sound\\cl38.wav",	//79					 (3)
	"\\data\\sound\\rd82b.wav",	//80					 (4)
	"\\data\\sound\\cl42.wav",	//81					 (5)
	"\\data\\sound\\rd82c.wav",	//82					 (6)
	"\\data\\sound\\rd84g.wav",	//83					 (7)
	"\\data\\sound\\cl35.wav",	//84					 (8)
	"\\data\\sound\\cl26.wav",	//85					 (9)
	"\\data\\sound\\rd82a.wav",	//86					 (10)
	"\\data\\sound\\cl37.wav",	//87					 (11)
	"\\data\\sound\\rd84b.wav",	//88					 (12)
	"\\data\\sound\\cl43.wav",	//89					 (13)
	"\\data\\sound\\cl47.wav",	//90					 (14)
	"\\data\\sound\\ai78a.wav",	//91					 (15)
//	"\\data\\sound\\rd146.wav",	//92					 (16)
	"\\data\\sound\\rd208.wav",	//92					 (16)
	"\\data\\sound\\rd147.wav",	//93					 (17)
	"\\data\\sound\\rd148.wav",	//94					 (18)
	"\\data\\sound\\rd145.wav",	//95					 (19)
	"\\data\\sound\\rd139.wav",	//96					 (20)
	"\\data\\sound\\rd140.wav",	//97					 (21)
	"\\data\\sound\\rd142.wav",	//98					 (22)
	"\\data\\sound\\rd143.wav",	//99					 (23)
	"\\data\\sound\\ai77d.wav",	//100					 (24)
	"\\data\\sound\\rd108.wav",	//101					 (25)
	"\\data\\sound\\rd138.wav",	//102					 (26)
	"\\data\\sound\\rd208.wav",	//103					 (27)

	"\\data\\sound\\rd83.wav",		//FIREWAL! 104-114 (0)
	"\\data\\sound\\rd88g.wav",	//105					 (1)
	"\\data\\sound\\cl36a.wav",	//106					 (2)
	"\\data\\sound\\rd86.wav",	//107					 (3)
	"\\data\\sound\\cl38b.wav",	//108					 (4)
	"\\data\\sound\\rd81.wav",	//109					 (5)
	"\\data\\sound\\cl58.wav",	//110					 (6)
	"\\data\\sound\\ai78d.wav",	//111					 (7)
	"\\data\\sound\\ai77b.wav",	//112					 (8)
	"\\data\\sound\\rd149.wav",	//113					 (9)
	"\\data\\sound\\rd209.wav",	//114					 (10)

	"\\data\\sound\\rd82a.wav",	// FIN CON! 115-125(0)
	"\\data\\sound\\cl36a.wav",	//116					 (1)
	"\\data\\sound\\rd82b.wav",	//117					 (2)
	"\\data\\sound\\cl36c.wav",	//118					 (3)
	"\\data\\sound\\rd82b.wav",	//119					 (4)
	"\\data\\sound\\rd106.wav",	//120					 (5)
	"\\data\\sound\\cl36b.wav",	//121					 (6)
	"\\data\\sound\\rd82b.wav",	//122					 (7)
	"\\data\\sound\\cl49.wav",	//123					 (8)
	"\\data\\sound\\rd83.wav",	//124					 (9)
	"\\data\\sound\\rd155.wav",	//125					 (10)

	"\\data\\sound\\cl53a.wav",	// INWALL! 126-132 (0)
//	"\\data\\sound\\cl51.wav",	//127					 (1)
	"\\data\\sound\\yelp.wav",	//127					 (1)
	"\\data\\sound\\cl52.wav",	//128					 (2)
	"\\data\\sound\\rd210.wav",	//129					 (3)
	"\\data\\sound\\rd211.wav",	//130					 (4)
	"\\data\\sound\\rd212.wav",	//131					 (5)
	"\\data\\sound\\rd213.wav",	//132					 (6)

	"\\data\\sound\\me71.wav",	// COL MES!133-138 (17)
	"\\data\\sound\\me72.wav",	//134					 (18)
	"\\data\\sound\\me73.wav",	//135					 (19)
	"\\data\\sound\\me74.wav",	//136					 (20)
	"\\data\\sound\\me75.wav",	//137					 (21)
	"\\data\\sound\\me76.wav"	//138					 (22)
};

long g_soundvol=127;
short g_playedclue[NUMCLUES];

void  *GetSceneMusicMemory(long amtreq);
void   FreeSceneMusicMemory();

long   LoadSceneMusic(long scenenumber);
void unLoadSceneMusic();
long playSceneMusic(void);
long  g_smmleftover=0; //Amount of scene music left over
void *g_smmemory = (void *) NULL;
void *g_smusicptr;   // Pointer to beginning of audio data for a scene's music
long  g_smusiclen=0; //The length of the scene music

long   LoadClues(void);
void unLoadClues(void);
long playClue(long cluetoplay);

long   LoadEffects(void);
void unLoadEffects(void);

long playMEClue(int x);
LONG RAW_read(LONG n);
void changeVolume(long vol);
HSAMPLE	smp[N_VOICES]; // Sample handles for each mixer channel


void	*snd[NUMEFFECT];  // Pointer to beginning of audio data for .WAV (fx)
LONG	siz[NUMEFFECT];  // Size of audio data in .WAV (fx)
long   g_numeffsmalloced=0;

void	*clueptr[32];  // Pointer to beginning of audio data for a clue
LONG    cluelen[32];	// Size of audio data for clue files
long   g_numcluesmalloced=0;

LONG	num_voices;	 // Actual number of mixer channels available

void	processSpecialClue(long clue);

//CSC June 18 1996
long g_soundloadflg=0;
void   LoadAllSound();
void unLoadALLSound();
void   LoadSomeSound();
long unLoadSomeSound();

#else

extern void *snd[];
extern void *clueptr[];

extern short g_playedclue[NUMCLUES];
extern HSAMPLE	smp[N_VOICES]; // Sample handles for each mixer channel
extern char *g_effectname[];
extern int initsound();
extern int loadeffects(void);
extern int loadsound(char *name);
extern long playSoundFX(long effect);
extern long loadSceneMusic(int x);
extern long playSceneMusic(void);
extern int loadClues(void);
extern void changeVolume(long vol);
extern long playClue(int x);
extern long playMEClue(int x);
extern long g_soundvol;
extern void	processSpecialClue(long clue);

extern long g_soundloadflg;
extern void   LoadSomeSound();
extern long unLoadSomeSound();

extern void   LoadAllSound();
extern void unLoadAllSound();
#endif
